<?php

define("dir",dirname(dirname(dirname(__FILE__)))."/");

require_once dir . "include/init.inc.php";

if (!App::isStaff())
{
	exit('No Dice!');
}

$filelist = array();
$dirname = str_replace("/plugins/system/htaccessgen.php","",$_SERVER['REQUEST_URI']);

if ($dirname != null)
	{
	$dirname = ltrim($dirname,'/') . "/";
	}

if ($dh = opendir(dir))
	{
	while (($file = readdir($dh)) !== false)
		{
		if ($file != '.' && $file != '..' && $file != '.htaccess')
			{
			array_push($filelist,$file);
			}
		}
	closedir($dh);
	}

sort($filelist);

$conditions = '';
$total = count($filelist);
$count = 0;

foreach ($filelist as $eachfile)
	{
	$count++;
	$fullfile = dir . $eachfile;
	if (is_dir($fullfile))
		{
		$conditions .= 'RewriteCond %{REQUEST_URI} !^/' . $dirname . $eachfile . '/.*';
		}
	else
		{
		$conditions .= 'RewriteCond %{REQUEST_URI} !^/' . $dirname . $eachfile . '$';;
		}
	if ($count < $total)
		{
		$conditions .= "<br>\n";
		}
	}


echo "RewriteEngine On<br><br>

$conditions<br>
RewriteRule ^index.php(/.*)$ /";

echo $dirname;
echo "index.php?do=$1 [L]<br><br>

$conditions<br>
RewriteRule ^(.*)$ /";

echo $dirname;

echo "index.php?do=/$1 [L]<br><br>";




?>